package org.sgx.gwteditors.testgallery.gallery;

import java.util.Map;

import org.sgx.gwteditors.client.editor.event.EditorValueChangeEvent;
import org.sgx.gwteditors.client.editor.event.ValueChangeListener;
import org.sgx.gwteditors.client.impl1.basetypes.SelectionList;
import org.sgx.gwteditors.client.impl1.complex.SelectionListSingleSelEditor;
import org.sgx.gwteditors.client.util.TestUtil;

import com.google.gwt.resources.client.ExternalTextResource;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;

public class SelectionListTest implements Test {	
	
	@Override
	public void test(Panel parent) {
		
		SelectionList<String> selList1 = new SelectionList<String>(new String[]{
			"uno", "dos", "tres", "cuatro"
		}, new String[]{"dos"});
		
		final SelectionListSingleSelEditor<String> ed1 = new SelectionListSingleSelEditor<String>();
		ed1.load(selList1);
		ed1.addValueChangeListener(new ValueChangeListener<SelectionList<String>>() {			
			@Override
			public void notifyValueChange(
					EditorValueChangeEvent<SelectionList<String>> evt) {
				Window.alert("selection detected: "+ed1.flush());
			}
		});
		
		FlexTable ft = new FlexTable();
		
		ft.setWidget(0, 0, new Label("single selection list editor: "));
		ft.setWidget(0, 1, ed1);
		
		parent.add(ft);
	}

	//test stuff
	@Override
	public String getName() {
		return "selection lists";
	}

	@Override
	public String[] getTags() {		
		return null;
	}

	@Override
	public String getDescription() {
		return "show both single and multiple selection list editors";
	}

	@Override
	public Map<String, ExternalTextResource> getJavaSources() {
		return TestUtil.getResource(getName(), TestResources.INSTANCE.SelectionListTest());
	}

//	@Override
//	public String[] getJavaSources() {
//		return new String[]{TestResources.INSTANCE.SelectionListTest().getText()};
//	}

}
